package com.bdqn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.mapper.NewsMapper;
import com.bdqn.pojo.News;
import com.bdqn.service.NewsService;
import org.springframework.stereotype.Service;

/**
 * 新闻Service实现
 *
 * @author LILIBO
 * @since 2024/10/10
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {

    /**
     * 模拟秒杀
     *
     * @param id
     * @return
     */
    @Override
    public News seckill(Long id) {
        News news = baseMapper.selectById(id);
        Integer version = news.getVersion();
        System.out.println("当前版本号：" + version);
        news.setCount(news.getCount() - 1);
        int result = baseMapper.updateById(news);
        if (result == 1) {
            System.out.println("秒杀成功！");
            return news;
        } else {
            System.out.println("秒杀失败！");
        }
        return null;
    }

}




